//
//  OperationBar.m
//  oschina_song
//
//  Created by song on 16/2/1.
//  Copyright © 2016年 song. All rights reserved.
//

#import "OperationBar.h"

@implementation OperationBar


-(id)init
{
    self = [super init];
    if(self)
    {
        [self setLayout];
    }
    
    return self;
}



-(void)setLayout
{
    
    NSMutableArray *items = [NSMutableArray new];
    
    NSArray *images = @[@"toolbar-keyboardUp", @"toolbar-separatorline", @"toolbar-comments", @"toolbar-editingComment", @"toolbar-star", @"toolbar-share", @"toolbar-report"];
    
    NSArray *selectors =@[@"swichMode:",@"",@"showComments:",@"editComment:",@"toggleStar:",@"share:",@"report:"];
    
    [images enumerateObjectsUsingBlock:^(NSString *imageName, NSUInteger idx, BOOL * _Nonnull stop) {
        
        UIImage *imgage = [UIImage imageNamed:imageName];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        btn.frame = CGRectMake(0, 0, imgage.size.width, imgage.size.height);
        [btn setBackgroundImage:imgage forState:UIControlStateNormal];
        [btn addTarget:self action:NSSelectorFromString(selectors[idx]) forControlEvents:UIControlEventTouchUpInside];
        UIBarButtonItem *baritem = [[UIBarButtonItem alloc] initWithCustomView:btn];
        [items addObject:baritem];
        [items addObject:[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]];
        
    }];
    
    
    [self setItems:items];
    
}

-(void)swichMode:(id)sender
{
    if(_swichMode){_swichMode();}
}

@end
